using System.ComponentModel;
using System.Windows.Forms;

namespace ApplicationLibrary.SqlConnector
{
    /// <summary>
    /// Summary description for ChgPwdForm.
    /// </summary>
    public class ChgPwdForm : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.AFSMaskedTextBox txtOldPwd;
        private System.Windows.Forms.AFSMaskedTextBox txtNewPwd;
        private System.Windows.Forms.AFSMaskedTextBox txtConfirmPwd;
        private System.Windows.Forms.Button btnCancel;
        private System.Windows.Forms.Button btnOk;

        private string oldpwd = string.Empty;
        private IContainer components = null;

        public string Password { get { return txtNewPwd.Text; } }

        public ChgPwdForm(string _oldpwd)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            oldpwd = _oldpwd;
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ChgPwdForm));
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.txtOldPwd = new System.Windows.Forms.AFSMaskedTextBox();
            this.txtNewPwd = new System.Windows.Forms.AFSMaskedTextBox();
            this.txtConfirmPwd = new System.Windows.Forms.AFSMaskedTextBox();
            this.btnCancel = new System.Windows.Forms.Button();
            this.btnOk = new System.Windows.Forms.Button();
            this.SuspendLayout();

            //
            // label1
            //
            resources.ApplyResources(this.label1, "label1");
            this.label1.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.label1.Name = "label1";

            //
            // label2
            //
            resources.ApplyResources(this.label2, "label2");
            this.label2.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.label2.Name = "label2";

            //
            // label3
            //
            resources.ApplyResources(this.label3, "label3");
            this.label3.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.label3.Name = "label3";

            //
            // txtOldPwd
            //
            this.txtOldPwd.Flags = 0;
            resources.ApplyResources(this.txtOldPwd, "txtOldPwd");
            this.txtOldPwd.Mask = "";
            this.txtOldPwd.Name = "txtOldPwd";
            this.txtOldPwd.ToUpper = false;
            this.txtOldPwd.UseSystemPasswordChar = true;

            //
            // txtNewPwd
            //
            this.txtNewPwd.Flags = 0;
            resources.ApplyResources(this.txtNewPwd, "txtNewPwd");
            this.txtNewPwd.Mask = "";
            this.txtNewPwd.Name = "txtNewPwd";
            this.txtNewPwd.ToUpper = false;
            this.txtNewPwd.UseSystemPasswordChar = true;

            //
            // txtConfirmPwd
            //
            this.txtConfirmPwd.Flags = 0;
            resources.ApplyResources(this.txtConfirmPwd, "txtConfirmPwd");
            this.txtConfirmPwd.Mask = "";
            this.txtConfirmPwd.Name = "txtConfirmPwd";
            this.txtConfirmPwd.ToUpper = false;
            this.txtConfirmPwd.UseSystemPasswordChar = true;

            //
            // btnCancel
            //
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            resources.ApplyResources(this.btnCancel, "btnCancel");
            this.btnCancel.Name = "btnCancel";

            //
            // btnOk
            //
            this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
            resources.ApplyResources(this.btnOk, "btnOk");
            this.btnOk.Name = "btnOk";

            //
            // ChgPwdForm
            //
            resources.ApplyResources(this, "$this");
            this.Controls.Add(this.btnOk);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.txtConfirmPwd);
            this.Controls.Add(this.txtNewPwd);
            this.Controls.Add(this.txtOldPwd);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            this.Name = "ChgPwdForm";
            this.Closing += new System.ComponentModel.CancelEventHandler(this.ChgPwdForm_Closing);
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        #endregion

        private void ChgPwdForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (this.DialogResult == DialogResult.OK)
            {
                if (Cryption.Encrypt(txtOldPwd.Text) != oldpwd)
                {
                    MessageBox.Show(
                        Properties.Resources.Password_Different,
                        Properties.Resources.Warning,
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true;
                }

                if (txtNewPwd.Text != txtConfirmPwd.Text)
                {
                    MessageBox.Show(
                        Properties.Resources.Password_Different,
                        Properties.Resources.Warning,
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true;
                }

                //if (txtNewPwd.Text.Trim() == string.Empty)
                //{
                //    MessageBox.Show(
                //        Properties.Resources.Password_NoBlank,
                //        Properties.Resources.Warning,
                //        MessageBoxButtons.OK, MessageBoxIcon.Error);
                //    e.Cancel = true;
                //}
            }
        }
    }
}